package net.sk.china.city.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArArticleCategory;
import net.sk.china.city.service.IArArticleCategoryService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 文章类别Controller
 * 
 * @author gxf
 * @date 2024-03-26
 */
@Api(tags = "文章类别")
@RequiredArgsConstructor
@RestController
@RequestMapping("/information/articleCategory")
public class ArArticleCategoryController extends BaseController
{
    @Autowired
    private IArArticleCategoryService arArticleCategoryService;

    /**
     * 查询文章类别列表
     */
    @ApiOperation("获取类别列表")
    @PreAuthorize("hasAnyAuthority('information:articleCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArArticleCategory arArticleCategory)
    {
        startPage();
        List<ArArticleCategory> list = arArticleCategoryService.selectArArticleCategoryList(arArticleCategory);
        return getDataTable(list);
    }

    /**
     * 导出文章类别列表
     */
//    @PreAuthorize("@ss.hasPermi('information:articleCategory:export')")
//    @Log(title = "文章类别", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ArArticleCategory arArticleCategory)
//    {
//        List<ArArticleCategory> list = arArticleCategoryService.selectArArticleCategoryList(arArticleCategory);
//        ExcelUtil<ArArticleCategory> util = new ExcelUtil<ArArticleCategory>(ArArticleCategory.class);
//        util.exportExcel(response, list, "文章类别数据");
//    }

    /**
     * 获取文章类别详细信息
     */
    @ApiOperation("类别详情")
    @PreAuthorize("hasAnyAuthority('information:articleCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arArticleCategoryService.selectArArticleCategoryById(id));
    }

    /**
     * 新增文章类别
     */
    @ApiOperation("新增类别")
    @PreAuthorize("hasAnyAuthority('information:articleCategory:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArArticleCategory arArticleCategory)
    {
        return toAjax(arArticleCategoryService.insertArArticleCategory(arArticleCategory));
    }

    /**
     * 修改文章类别
     */
    @ApiOperation("修改类别")
    @PreAuthorize("hasAnyAuthority('information:articleCategory:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArArticleCategory arArticleCategory)
    {
        return toAjax(arArticleCategoryService.updateArArticleCategory(arArticleCategory));
    }

    /**
     * 删除文章类别
     */
    @ApiOperation("删除类别")
    @PreAuthorize("hasAnyAuthority('information:articleCategory:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arArticleCategoryService.deleteArArticleCategoryByIds(ids));
    }

    /**
     * 获取所有类别名和id
     */
    @ApiOperation("类别名和id")
    @GetMapping("/getNameAndId")
    public AjaxResult getNameAndId()
    {
        return success(arArticleCategoryService.getNameAndId());
    }

//    @ApiOperation("修改类别状态")
//    @PreAuthorize("@ss.hasPermi('information:articleCategory:edit')")
//    @PostMapping("/updateStatus")
//    public AjaxResult updateStatus(@RequestBody ArArticleCategory arArticleCategory)
//    {
//        return success(arArticleCategoryService.updateStatus(arArticleCategory));
//    }
}
